* cd "" (set working directory)
use "Data/grammar_schools_panel.dta", clear
set matsize 11000

xtset hundred year, delta(1)

* MAIN REGRESSIONS

xtreg grammar monasteryxpost i.year, fe robust
outreg2 using grammar.doc, replace nocon tex dec(4) addtext(Hundred FE, Yes, Year FE, Yes, County trends, No) keep(monasteryxpost)

xtreg  grammar monasteryxpost i.year i.cty##c.year, fe robust
outreg2 using grammar.doc, append nocon tex dec(4) addtext(Hundred FE, Yes, Year FE, Yes, County trends, Yes) keep(monasteryxpost)

xtreg grammar monasteryxpost monasteryxpostxtrend i.year, fe robust
outreg2 using grammar.doc, append nocon tex dec(4) addtext(Hundred FE, Yes, Year FE, Yes, County trends, No) keep(monasteryxpost monasteryxpostxtrend)

xtreg grammar monasteryxpost monasteryxpostxtrend i.year i.cty##c.year, fe robust
outreg2 using grammar.doc, append nocon tex dec(4) addtext(Hundred FE, Yes, Year FE, Yes,County trends, Yes) keep(monasteryxpost monasteryxpostxtrend)

* LOG GRAMMAR (appendix)
xtreg loggrammar monasteryxpost i.year, fe robust
outreg2 using grammar2.doc, replace nocon tex dec(4) addtext(Hundred FE, Yes, Year FE, Yes, County trends, No) keep(monasteryxpost)

xtreg loggrammar monasteryxpost i.year i.cty##c.year, fe robust
outreg2 using grammar2.doc, append nocon tex dec(4) addtext(Hundred FE, Yes, Year FE, Yes, County trends, Yes) keep(monasteryxpost)

xtreg loggrammar monasteryxpost monasteryxpostxtrend i.year, fe robust
outreg2 using grammar2.doc, append nocon tex dec(4) addtext(Hundred FE, Yes, Year FE, Yes, County trends, No) keep(monasteryxpost monasteryxpostxtrend)

xtreg loggrammar monasteryxpost monasteryxpostxtrend i.year i.cty##c.year, fe robust
outreg2 using grammar2.doc, append nocon tex dec(4) addtext(Hundred FE, Yes, Year FE, Yes,County trends, Yes) keep(monasteryxpost monasteryxpostxtrend)


* CONTINUOUS MEASURE OF INCOME (appendix)
xtreg grammar incomexpost i.year, fe robust
outreg2 using income_continuous.doc, replace nocon tex dec(4) addtext(Hundred FE, Yes, Year FE, Yes, County trends, No) keep(incomexpost)

xtreg  grammar incomexpost i.year i.cty##c.year, fe robust
outreg2 using income_continuous.doc, append nocon tex dec(4) addtext(Hundred FE, Yes, Year FE, Yes, County trends, Yes) keep(incomexpost)

xtreg grammar incomexpost incomexpostxtrend i.year, fe robust
outreg2 using income_continuous.doc, append nocon tex dec(4) addtext(Hundred FE, Yes, Year FE, Yes, County trends, No) keep(incomexpost incomexpostxtrend)

xtreg grammar incomexpost incomexpostxtrend i.year i.cty##c.year, fe robust
outreg2 using income_continuous.doc, append nocon tex dec(4) addtext(Hundred FE, Yes, Year FE, Yes,County trends, Yes) keep(incomexpost incomexpostxtrend)


* LOG GRAMMAR SCHOOLS & CONTINUOUS MEASURE OF INCOME (appendix)
xtreg loggrammar incomexpost i.year, fe robust
outreg2 using income_continuous2.doc, replace nocon tex dec(4) addtext(Hundred FE, Yes, Year FE, Yes, County trends, No) keep(incomexpost)

xtreg  loggrammar incomexpost i.year i.cty##c.year, fe robust
outreg2 using income_continuous2.doc, append nocon tex dec(4) addtext(Hundred FE, Yes, Year FE, Yes, County trends, Yes) keep(incomexpost)

xtreg loggrammar incomexpost incomexpostxtrend i.year, fe robust
outreg2 using income_continuous2.doc, append nocon tex dec(4) addtext(Hundred FE, Yes, Year FE, Yes, County trends, No) keep(incomexpost incomexpostxtrend)

xtreg loggrammar incomexpost incomexpostxtrend i.year i.cty##c.year, fe robust
outreg2 using income_continuous2.doc, append nocon tex dec(4) addtext(Hundred FE, Yes, Year FE, Yes,County trends, Yes) keep(incomexpost incomexpostxtrend)


* Conley standard errors
acreg grammar monasteryxpost, time(year) id(id) spatial hac latitude(lat) longitude(lon) dist(100) lagcut(10000) pfe1(id) pfe2(year)
acreg grammar monasteryxpost monasteryxpostxtrend, time(year) id(id) spatial hac latitude(lat) longitude(lon) dist(100) lagcut(10000) pfe1(id) pfe2(year)


* Event study analysis (appendix)

gen pre1 = 0
replace pre1 = 1 if year>1520 & year<=1530

gen pre2 = 0
replace pre2 = 1 if year>1510 & year<=1520

gen pre3 = 0
replace pre3 = 1 if year>1500 & year<=1510

gen pre4 = 0
replace pre4 = 1 if year>1490 & year<=1500

gen pre5 = 0
replace pre5 = 1 if year>=1480 & year<=1490

gen post0 = 0
replace post0 =1 if year>1530 & year<=1540

gen post1 = 0
replace post1 = 1 if year>1540 & year<=1550

gen post2 = 0
replace post2 = 1 if year>1550 & year<=1560

gen post3 = 0
replace post3 = 1 if year>1560 & year<=1570

gen post4 = 0
replace post4 = 1 if year>1570 & year<=1580

gen post5 = 0
replace post5 = 1 if year>1580 & year<=1590

gen post6 = 0
replace post6 = 1 if year>1590 & year<=1600

gen post7 = 0
replace post7 = 1 if year>1600 & year<=1610

gen post8 = 0
replace post8 = 1 if year>1610 & year<=1620

gen post9 = 0
replace post9 = 1 if year>1620 & year<=1630

gen post10 = 0
replace post10 = 1 if year>1630 & year<=1640


foreach x in pre1 pre2 pre3 pre4 pre5 post0 post1 post2 post3 post4 post5 post6 post7 post8 post9 post10 {
replace `x' = 0 if monastery==0
}

* EVENT STUDY PLOT (appendix)
xtreg grammar pre5 pre4 pre3 pre2 post0 post1 post2 post3 post4 post5 post6 post7 post8 post9 post10 i.year if year<=1610, fe robust
coefplot, keep(pre* post*) vertical yline(0) level(99)

